package cn.lili.modules.order.order.entity.dto;


import cn.hutool.core.text.CharSequenceUtil;
import cn.lili.common.enums.PromotionTypeEnum;
import cn.lili.modules.order.cart.entity.enums.CartSceneEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
 * 加入购物车参数
 *
 * @author liushuai(liushuai711 @ gmail.com)
 * @version v4.0
 * @Description:
 * @since 2022/10/11 15:14
 */
@Data
@Slf4j
public class CartParamsDTO {

    @NotNull(message = "产品id不能为空")
    @ApiModelProperty(value = "商品SKUID")
    private String skuId;

    @NotNull(message = "购买数量不能为空")
    @Min(value = 1, message = "加入购物车数量必须大于0")
    @ApiModelProperty(value = "数量")
    private Integer num;

    @ApiModelProperty(value = "分销商Id")
    private String distributionId;

    @ApiModelProperty(value = "是否覆盖购物车的数量，如果 true 直接覆盖，否则累加")
    private Boolean cover;

    /**
     * @see cn.lili.modules.order.cart.entity.enums.CartSceneEnum
     */
    @ApiModelProperty(value = "购物车类型")
    private String way;

    /**
     * @see PromotionTypeEnum
     */
    @ApiModelProperty(value = "参与促销枚举 如不设置，且存在拼团、积分、砍价以外的活动，则会自动参与一项（顺序以map中促销的优先级为准）")
    private PromotionTypeEnum promotionType;

    /**
     * 是否选中
     */
    private Boolean checked;

    public Boolean getCover() {
        if (cover == null) {
            return true;
        }
        return cover;
    }

    public CartSceneEnum cartSceneEnum() {
        //默认购物车
        CartSceneEnum cartSceneEnum = CartSceneEnum.CART;
        if (CharSequenceUtil.isNotEmpty(way)) {
            try {
                cartSceneEnum = CartSceneEnum.valueOf(way);
            } catch (IllegalArgumentException e) {
                log.error("获取购物车类型出现错误：", e);
            }
        }
        return cartSceneEnum;
    }
}
